<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
    <title>人员报名</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <script th:src="@{/layui/layui.js}"></script>
    <style>
        form {
        margin: 30px;
        }
    </style>

</head>

<body>
    <img src="/image/nb.png" width="200px" height="50px">
    <form id="addStudentForm" class="layui-form" action="/student/saveStudentForm" onsubmit="return dosubmit()" method="post">
        <input hidden="hidden" id="count" th:value="${businessHospital.count}">
        <input hidden="hidden" name="businessId" th:value="${businessHospital.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">活动名称</label>
            <div class="layui-input-block">
                <input type="text" readonly="readonly"  th:value="${businessHospital.name}" required lay-verify="required"  autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人员姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入人员姓名" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人员年龄</label>
            <div class="layui-input-block">
                <input type="text" name="age" required lay-verify="required|number" placeholder="请输入人员年龄" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学校/单位</label>
            <div class="layui-input-block">
                <input type="text" name="school" required lay-verify="required" placeholder="请输入人员学校" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone" required lay-verify="required|phone" placeholder="请输入手机号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveStudentFilter">立即报名</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</body>
<script type="text/javascript" th:inline="javaScript">
    layui.use(['jquery'], function(){
        var $ = layui.jquery;
        //判断报名人数是否已满
        let  count=[[${businessHospital.count}]];
        let  countAlready=[[${countAlready}]];

        console.log("count:"+count)
        console.log("countAlready:"+countAlready)
        if(countAlready>=count){
            alert("(*╹▽╹*)抱歉,名额已满!");
            window.location.href="error.html";
        }
        //判断活动是否开始
        var now =Date.parse(new Date());
        let  begin=Date.parse([[${businessHospital.begin}]]);
        let  end=Date.parse([[${businessHospital.end}]]);
        console.log(now+"||"+begin+"||"+end);
        if(now<begin){
            alert("(*╹▽╹*)抱歉,活动未开始!");
            window.location.href="error.html";
        }
        //判断活动是否结束
        if(now>end){
            alert("(*╹▽╹*)抱歉,活动已经结束!");
            window.location.href="error.html";
        }

    })

    //默认提交状态为false
    var commitStatus = false;
    function dosubmit(){

        if(commitStatus==false){
            //提交表单后，将提交状态改为true
            commitStatus = true;
            return true;
        }else{
            return false;
        }
    }
</script>
</html>